<template>
  <div class="tab-control">
    <span
      class="tab-control-item"
      :class="{ active: index === currentIndex }"
      @click="itenClick(index)"
      v-for="(item, index) in titles"
      :key="index"
      >{{ item }}</span
    >
  </div>
</template>

<script>
export default {
  props: {
    titles: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      currentIndex: 0,
    };
  },
  methods: {
    itenClick(index) {
      this.currentIndex = index;
      this.$emit("tabClick", index);
    },
  },
};
</script>

<style scoped>
.tab-control {
  display: flex;
  text-align: center;
  height: 40px;
  line-height: 40px;
  background: #fff;
}
.tab-control-item {
  flex: 1;
}
.active {
  color: var(--color-high-text);
}
.active::after {
  content: "";
  display: block;
  border-bottom: 3px solid var(--color-tint);
  width: 50px;
  margin: 0 auto;
}
</style>
